package top.tangyh.lamp.care.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.tangyh.basic.base.R;
import top.tangyh.lamp.care.service.BObsvRecordService;
import top.tangyh.lamp.care.service.clickhouse.IotDataService;
import top.tangyh.lamp.care.vo.query.VyxIcuVsDataByHisParam;
import top.tangyh.lamp.care.vo.result.IotDataResult;

import javax.validation.Valid;
import java.util.List;

/**
 * @author: zqb
 * @date: 2024/11/29 09:14
 */
@Slf4j
@RequiredArgsConstructor
@Validated
@RestController
@RequestMapping("/obsvCkCollection")
@Tag(name = "观察项数据采集")
public class ObsvCKDataCollectionController {

    private final IotDataService iotDataService;

    private final BObsvRecordService bObsvRecordService;

    @Operation(summary="采集历史时间点的观察项数据")
    @PostMapping("/collect/his")
    public R<Boolean> collectHis(@RequestBody @Valid VyxIcuVsDataByHisParam param) throws Exception {

        List<IotDataResult> iotDataList= iotDataService.getCustomCollectionByHospitalNumberAndTimePoint(param.getHospitalNumber(),param.getTimePointList());

        Boolean result=bObsvRecordService.IotDataCollectionOfSave(iotDataList);
        return   R.success(result);
    }

    @Operation(summary="测试采集历史时间点的观察项数据")
    @PostMapping("test/collect/his")
    public R< List<IotDataResult>> testCollectHis(@RequestBody @Valid VyxIcuVsDataByHisParam param) throws Exception {

        List<IotDataResult> iotDataList= iotDataService.getCustomCollectionByHospitalNumberAndTimePoint(param.getHospitalNumber(),param.getTimePointList());


        return   R.success(iotDataList);
    }


    @Operation(summary="测试时间查询结果 ")
    @PostMapping("test/SelectTime")
    public R< String> SelectTime() throws Exception {

        String time= iotDataService.selectTimeTest();
        return   R.success(time);
    }
}
